<template>
<el-form :model="editForm"  label-width="120px" :rules="editFormRules" ref="editFormRef">
    <el-form-item label="目标企业" prop="branchId">
        <mdp-select-table placeholder="目标机构" v-model="editForm.branchId" :props="{id:'id',name:'branchName'}" :disabled="!userInfo.isSuperAdmin && !userInfo.isPlatformAdmin"
                      :init-name="userInfo.branchName" :load-fun="$mdp.listBranch" @change2="onBranchChange"/>
    </el-form-item> 
    
    <el-form-item label="续会时间" prop="rtime">
        <el-input  v-model="editForm.rtime" placeholder="下次续会时间YYYY-MM-DD型" :maxlength="10" @change="editSomeFields(editForm,'rtime',$event)" :disabled="  disField"/>
    </el-form-item> 
    <el-form-item label="审核状态" prop="flowState">
        <mdp-select itemCode="bizFlowState"  v-model="editForm.flowState" placeholder="当前流程状态" :maxlength="1" @change="editSomeFields(editForm,'flowState',$event)" :disabled="  disField"/>
    </el-form-item>
    
    <el-form-item label="企业人数上限" prop="maxUsers">
        <el-input-number  v-model="editForm.maxUsers" :min="0"  :precision="0" @change="editSomeFields(editForm,'maxUsers',$event)" :disabled="  disField"/>
    </el-form-item>
    <el-form-item label="当前企业人数" prop="currUsers">
        <el-input-number  v-model="editForm.currUsers" :min="0"  :precision="0" @change="editSomeFields(editForm,'currUsers',$event)" :disabled=" true|| disField"/>
    </el-form-item>
    <el-form-item label="续费截止时间" prop="maxRtime">
        <el-input  v-model="editForm.maxRtime" placeholder="产品模块下次续费截止时间YYYY-MM-DD类型" :maxlength="10" @change="editSomeFields(editForm,'maxRtime',$event)" :disabled="  disField"/>
    </el-form-item>
    <el-form-item label="产品版本" prop="mver">
        <mdp-select itemCode="menuSupVers"  v-model="editForm.mver" placeholder="产品版本 免费版 企业版" :maxlength="1" @change="editSomeFields(editForm,'mver',$event)" :disabled="  disField"/>
    </el-form-item>
    
    <el-form-item label="创建时间" prop="ctime">
        <el-date-picker type="date" placeholder="选择日期"  v-model="editForm.ctime"  value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD" :disabled="true||  disField"/>
    </el-form-item>
    <el-form-item label="更新时间" prop="ltime">
        <el-date-picker type="date" placeholder="选择日期"  v-model="editForm.ltime"  value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD" :disabled=" true|| disField"/>
    </el-form-item>
</el-form>
<el-row v-if="showBtn!==false" class="footer">
    <el-button @click="close" icon="close">关闭</el-button>
    <el-button icon="submit" v-if="currOpType=='add'" v-loading="load.edit" type="primary" @click="saveSubmit" :disabled="disBtn('addBtn') || !checkBtnQx('addBtn',menuDefId) || load.edit">提交</el-button>
</el-row>
</template>

<script>
import * as BranchInterestsApi from '@/api/mdp/sys/branchInterests';
import { MdpFormMixin } from '@/components/mdp-ui/mixin/MdpFormMixin.js';
import { mapState } from 'pinia'
import { useUserStore } from '@/store/modules/user'

export default {
    name:'BranchInterestsForm',
    mixins:[MdpFormMixin],
    components: {
    },
    computed: {
        ...mapState(useUserStore,['userInfo'])
    },
    props:{
        subOpType:{
            type: String,
            default: 'edit'
        }
    },
    watch: {
    },
    data() {
        return {
            menuDefId:'',//menu_def.id 菜单表菜单编号，用于按钮权限判断
            pkNames:["branchId"],//表格主键的java属性名称，驼峰命名，默认为id,支持多主键
            
            editFormRules: {
                branchId:[
                //{ required: true, message: '此项必填', trigger: 'change' },
                //{ min: 1,max: 200, message: '长度在1到200之间', trigger: 'change'}
                ]
            },
            editForm: {
                branchId:'',ilvlId:'',ilvlName:'',idesc:'',ilevel:'',discount:'',istatus:'',ctime:'',ltime:'',picUrl:'',isFree:'',rtimeRule:'',rtimeType:'',rtime:'',itype:'',shopId:'',instId:'',flowState:'',smaxAt:'',totalAt:'',mtype:'',totalExp:'',smaxExp:'',bids:'',sfeeRate:'',idBak:'',ctotalExp:'',ctotalAt:'',ctotalBids:'',mfee:'',maxUsers:'',currUsers:'',maxRtime:'',mver:'',guardId:'',srvTimes:'',guardName:'',guardRtime:'',cmonthBids:'',cmonthAt:'',cmonthExp:'',ctotalReceiveAt:'',csixExp:'',csixAt:'',csixBids:'',clearTime:''
            },
            //增删改查(含批量)接口
            apis:{
                queryById: this.$mdp.getBranchInterestsDetail, 
                editSomeFields: this.$mdp.editSomeFieldsBranchInterests
            },
        }
    },
    methods: {
        onBranchChange(branch){
            this.reloadBranchInterests(branch.id)
        },
        reloadBranchInterests(branchId){
            this.apis.queryById({branchId:branchId}).then(res=>{
                let {data,tips} = res
                if(tips.isOk){
                    this.editForm=data
                    Object.assign(this.dataBak,data)
                    this.currOpType='edit'
                }else{
                    this.$message.error(tips.msg)
                }
            })
        },
         //由组件扩展添加其它的初始页面的逻辑(mounted+onOpen都会调用此函数，建议只添加公共逻辑)
         initCurrData(){
            this.reloadBranchInterests(this.userInfo.branchId)
         },
        /**
         * 检查参数是否满足调用后台接口的条件
         * @returns true / false
         */
        preParamCheck(params){
            return true;
        },
        /**
         * 对修改的字段进行判断，返回false ,将取消更新数据库,由组件扩展
         * @param {*} row 当前选中的行
         * @param {*} fieldName 修改的字段名
         * @param {*} $event 修改后的值
         * @param {*} params 将要提交服务器的参数
         * @returns true/false 返回false ,将取消更新数据库
         */
        editSomeFieldsCheck(row,fieldName,$event,params){
            if(this.editable==false){
                return false;
            }
            params[fieldName]=$event
            return true;
        },
    },
    mounted() {

    }
}

</script>

<style scoped>

</style>